<%--
  Created by IntelliJ IDEA.
  User: 陌·笙
  Date: 2018-12-30
  Time: 17:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>采购审核</title>
    <jsp:include page="/comm/tag.jsp"/>
    <script>
        $(function(){
            $("#mytable").bootstrapTable({
                url:"/auditAndreview/showAudits",
                height:430,
                pageSize:6,
                pageNumber:1,
                pageList:[6],
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        seat:$("[name='seat']").val(),
                        StateId:2,
                        lasttime:$("[name='lasttime']").val(),
                        times:$("[name='times']").val(),
                    };
                    return temp;
                },
                locale:'zh-CN',//中文支持,
                toolbar:'#top',
                columns:[
                    {field:"seat",title:"单号",align:"center"},
                    {field:"auditTime",title:"开单日期",align:"center"},
                    {field:"presetPrice",title:"应付金额",align:"center"},
                    {field:"price",title:"实付金额",align:"center"},
                    {field:"sums",title:"总数量",align:"center"},
                    {field:"admin.aname",title:"经办人",align:"center"},
                    {field:"verifier",title:"审核人",align:"center"},
                    {field:"state.stateName",title:"状态",align:"center"},
                    {
                        title: "操作",
                        align: "center",
                        formatter: function (value, row, index) {
                            return "<button class=\"btn btn-primary\" onclick=\"ups('"+row.seat+"')\" > <span class=\"glyphicon glyphicon-wrench\"></span>&nbsp;&nbsp;审核</button>"
                        }
                    }
                ]
            })
        })
        function cha(){
            var opts = $("#mytable").bootstrapTable("getOptions") ;
            var seat=$("[name='seat']").val();
            var lasttime=$("[name='lasttime']").val();
            var times=$("[name='times']").val();
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            $.ajax({
                url:"/auditAndreview/showAudits",
                type:"get",
                data:{"seat":seat,"StateId":2,"lasttime":lasttime,"times":times,'limit':limit,'offset':offset},
                success:function(data){
                    $("#mytable").bootstrapTable("load",data);
                }
            })
        }
        function ups(seats) {
            swal({
                title: "您确定要审核这条信息吗",
                text: "请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "审核",
                closeOnConfirm: false
            }, function () {
                var opts = $("#mytable").bootstrapTable("getOptions") ;
                var seat=$("[name='seat']").val();
                var lasttime=$("[name='lasttime']").val();
                var times=$("[name='times']").val();
                var limit = opts.pageSize ;
                var offset = (opts.pageNumber-1) * limit;
                $.ajax({
                    type:"post",
                    url:"/auditAndreview/upStateId",
                    data:{"seats":seats,"seat":seat,"lasttime":lasttime,"times":times,'limit':limit,'offset':offset,"StateId":2},
                    success:function(data){
                        $("#mytable").bootstrapTable("load",data);
                        $.ajax({
                            url:"/auditAndreview/showReview",
                            type:"post",
                            data:{"seat":seat,'limit':6,'offset':0,"StateId":2},
                            success:function(data){
                                $("#detail").bootstrapTable("load",data);
                            }
                        })
                    }
                })
                swal("审核成功！", "您已经审核了这条单号", "success");
            })

        }
        $(function(){
            $("#detail").bootstrapTable({
                url:"/auditAndreview/showReview",
                height:430,
                pageSize:6,
                pageNumber:1,
                pageList:[6],
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        StateId:2,
                        seat:$("[name='seat']").val(),
                    };
                    return temp;
                },
                locale:'zh-CN',//中文支持,
                toolbar:'#top',
                columns:[
                    {field:"seat",title:"单号",align:"center"},
                    {field:"shop.shopName",title:"商品名称",align:"center"},
                    {field:"shop.shopcolor",title:"商品颜色",align:"center"},
                    {field:"shop.shopType",title:"商品型号",align:"center"},
                    {field:"shop.shopprice",title:"商品进价",align:"center"},
                    {field:"reviewNum",title:"购买数量",align:"center"},
                    {field:"reviewTotal",title:"总价",align:"center"},
                    {field:"firm.firmName",title:"供货商",align:"center"},
                ]
            })
        })
    </script>
    <%--双击事件--%>
    <script>
        // 双击表格一行事件
        $(document).on('dblclick', '#mytable tbody tr', function () {
            // 当前的tr
            var trElem = $(this);
            // 当前tr的index
            var index = trElem.data('index');
            // 找到这个table的view
            var tableView = trElem.parents('#mytable').first();
            // do something
            var seat=$(this).children().eq(0).html();//获取到单号
            $.ajax({
                type:"post",
                url:"/auditAndreview/showReview",
                data:{"seat":seat,"offset":0,"limit":6,"StateId":2},
                success:function (data) {
                    $("#detail").bootstrapTable("load",data);
                }
            })

        });
    </script>
</head>
<body>
<div style="margin-left: 50px;margin-right: 50px">
    <div class="#top" style="margin-top: 30px">
        <div class="col-md-11">
            <form action="" method="post" role="form" class="form-horizontal">
                <div class="form-group col-md-4">
                    <label for="" class="col-md-4 control-label">单号查询:</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" name="seat" placeholder="可模糊查询">
                    </div>
                </div>
                <div class="form-group col-md-7">
                    <label for="" class="col-md-4 control-label">时间查找:</label>
                    <div class="col-md-8">
                        <div class="col-md-6">
                            <input type="date" class="form-control" name="lasttime">
                        </div>
                        <label for="" class="col-md-1 control-label">至</label>
                        <div class="col-md-5">
                            <input type="date" class="form-control" name="times">
                        </div>
                    </div>
                </div>
                <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-search" onclick="cha()">查询</button>
            </form>
        </div><%--搜索框--%>
    </div>
    <table id="mytable" class="table-striped"></table>
    <table id="detail" class="table-striped"></table>
</div>
</body>
</html>
